package com.ljc.cjgl.security;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;

import org.springframework.data.annotation.CreatedBy;

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class SysGroup {
	private Integer id;
	private String name;
	private SysGroup parent;
	private Float sort;
	private List<SysGroup> children=new ArrayList<>();
	@Id
	@GeneratedValue
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	@ManyToOne
	@CreatedBy
	public SysGroup getParent() {
		return parent;
	}
	public void setParent(SysGroup parent) {
		this.parent = parent;
	}
	
	@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY)
	@JoinColumn(name="parent_id")
	@OrderBy(value="sort")
	public List<SysGroup> getChildren() {
		return children;
	}
	
	public void setChildren(List<SysGroup> children) {
		this.children = children;
	}
	
	public Float getSort() {
		return sort;
	}
	
	public void setSort(Float sort) {
		this.sort = sort;
	}
	
	
}
